package com.example.demo0310.controller;

import com.example.demo0310.entity.Student;
import com.example.demo0310.service.StudentService;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService service;

    /**
     * 查询
     */
    @GetMapping("/getInfo")
    public Student getStudent(@Param("id") Integer id) {
        Student student = service.findByID(id);
        return student;
    }

    @GetMapping("/getName")
    public Student getName(@Param("name") String name) {
        Student student = service.findByName(name);
        return student;
    }

    @GetMapping("/getAll")
    public List<Student> getAll() {
        List<Student> studentList = service.selectAll();
        return studentList;
    }

    /**
     * 删除
     */
    @GetMapping("/getdetele")
    public boolean deteleId(@Param("id") Integer id) {
        boolean state = service.deleteID(id);
        return state;
    }

    /**
     * 修改
     */
    @GetMapping("/getupdate")
    public boolean UpdateId(@Param("id") Integer id, @Param("name") String name) {
        boolean state = service.UpdateID(id, name);
        return state;
    }

    /**
     * 新增
     */
    @GetMapping("/getinsert")
    public boolean insertData(@Param("id") Integer id, @Param("name") String name, @Param("age") Integer age, @Param("score") Double score, @Param("birthday") String birthday) {
        boolean state = service.InsertData(id, name, age, score, birthday, null);
        return state;
    }
}
